package com.ironman.compute.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * description
 * company 铁人科技
 *
 * @author 陈浩杰
 * @date 2023/5/9 18:07
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "sailing")
public class SailingStandardProperties {

    private Map<String, SailingStandard> standard = new HashMap<>();

    public SailingStandard sailingStandard(Double windSpeed) {
        if (Objects.isNull(windSpeed)) {
            return null;
        }
        for (String range : standard.keySet()) {
            String[] split = range.split("-");
            int min = Integer.parseInt(split[0]);
            int max = Integer.parseInt(split[1]);
            if (windSpeed > min && windSpeed <= max) {
                return standard.get(range);
            }
        }
        return null;
    }
}
